<?php
namespace Before\Controller;
use Think\Controller;
class IndexController extends Controller {


	public function _initialize(){
		//cookie('uid',1);
	}


//===== 公用 

	//根据服务id 获取其模型实例
	public function get_m($service_id){
		$m = M('service_type');
		$res = $m->select();
		foreach($res as $v){
			if($service_id == $v['type_id']){
				return M($v['table_name']);
			}
		}
	}



//===== service_detail 相关

	public function service_detail_content(){
		$detail_type = I('get.detail_type');
		$info_id = I('get.info_id');
		$service_id = I('get.service_id');
		$file_name = I('get.file_name');
		$m_temp = $this->get_m($service_id);
		switch($service_id){
			case '24':	
			//	$field = 'info_ctime,info_imgs,info_stat,info_title,info_content,info_contacts,info_phone,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type,info_cond_price,info_cond_edu,info_cond_experience,info_cond_industry';
				$field = '';
			break;
			case '30':	
				$field = 'info_ctime,info_imgs,info_stat,info_title,info_content,info_contacts,info_phone,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type,info_cond_price,info_cond_industry';
			break;
			case '25':	
				$field = 'info_ctime,info_imgs,info_stat,info_title,info_content,info_contacts,info_phone,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type,info_cond_price,info_cond_shape,info_cond_area';
			break;
			case '26':	
				$field = 'info_ctime,info_imgs,info_stat,info_title,info_content,info_contacts,info_phone,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type,info_cond_price,info_cond_animal_type';
			break;
			case '29':	
				//$field = 'info_ctime,info_imgs,info_stat,info_title,info_content,info_contacts,info_phone,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type';
				$field = '';
			break;
			case '27':	
				$field = 'info_ctime,info_imgs,info_stat,info_title,info_content,info_contacts,info_phone,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type,info_cond_price,info_cond_goods_type';
			break;
			case '28':	
				//$field = 'info_ctime,info_imgs,info_stat,info_title,info_content,info_contacts,info_phone,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type,info_cond_price,info_cond_car_type,info_cond_brand,info_cond_use_year';
				$field = '';
			break;
		}
		$data = $m_temp->field($field)->find($info_id);
		//dump($data);
		//$data['info_imgs'] = json_decode($data['info_imgs'],1);
		$arr_imgs = json_decode($data['info_imgs'],1);
		foreach($arr_imgs as $v){
			$arr_imgs2[] = $v.'!be';
		}
		$data['info_imgs'] = $arr_imgs2;
		if(!$data || $data['info_stat'] != 2){
			if($detail_type == 'service_index'){
				$this->assign('data','error');
			}else if($detail_type == 'service_me'){
				$this->assign('data',$data);
			}
		}else{
			$this->assign('data',$data);
		}
		//echo $content = $this->fetch('Index/Service_detail/service_detail_content');
		echo $content = $this->fetch();
		if(!is_dir('Service/Template/Service_detail')){
			mkdir('Service/Template/Service_detail','0755',true);
		}
		file_put_contents("Service/Template/Service_detail/{$file_name}.html", $content);
	}








//===== service_me 相关

	//加载服务
	public function service_me_content(){
		$m_serviceType = M('Service_type');
		$res_serviceType = $m_serviceType->select();
		$this->assign('res_serviceType',$res_serviceType);
		$this->assign('uid',cookie('uid'));
		//echo $data = $this->fetch('Index/Service_me/service_me_content');
		echo $data = $this->fetch();
		file_put_contents('Service/Template/Service_me/service_me_content.html', $data);
	}


	//加载信息列表
	public function service_me_content_infos(){
		$uid = cookie('uid');
		if(!session('me_infos')){
			$m = M('tp_user_issue_infos');
			$data = $m->field('infos')->where(array('uid'=>$uid))->find();
			$me_infos = json_decode($data['infos'],1);
			session('me_infos',$me_infos);
		}
		//dump(session('me_infos'));exit;
		$pnow = I('get.pnow')?:1;	//当前页
		if(session('me_infos')){
			$pcount = count(session('me_infos'));		//总条数
			$psize = 6;						//每页条数
			$pnum = ceil($pcount / $psize);	//总页数
			$start = $pnow > 3? $pnow -2 : 1;
			$end = $pnow + 2 < $pnum ? $pnow<3&&$pnum>=5?5:$pnow + 2 : $pnum;
			$fpage .= "<a style='padding:3px 5px;border:1px solid;margin:3px;color:#aaa' pnow='1'>首页</a>";
			for($i=$start;$i<=$end;$i++){
				if($pnow == $i){
					$fpage .= "<a style='padding:3px 5px;border:1px solid;margin:3px;background:blue;color:#fff' pnow='{$i}'>{$i}</a>";
				}else{
					$fpage .= "<a style='padding:3px 5px;border:1px solid;margin:3px;color:#aaa' pnow='{$i}'>{$i}</a>";
				}
			}
			$fpage .= "<a style='padding:3px 5px;border:1px solid;margin:3px;color:#aaa' pnow='{$pnum}'>尾页</a>";
			$this->assign('fpage',$fpage);
		}
		$index_start = ($pnow-1) * $psize;
		$index_end = ($index_start + $psize);
		foreach(session('me_infos') as $k=>$v){
			if($k >= $index_start && $k < $index_end){
				$infos2[] = $v;
			}
		}

		$data3 = array();
		foreach($infos2 as $v){
			$m = $this->get_m($v['service_id']);
			$data2 = $m->find($v['info_id']);
			array_push($data3,$data2);
		}
		$this->assign('data3',$data3);
		echo $contents = $this->fetch();
		$path = 'Service/Template/Service_me/'.cookie('uid');
		$file_name = $path.'/'.$pnow.'.html';
		if(!is_dir($path)){
			mkdir($path,'0777',true);
		}
		file_put_contents($file_name, $contents);

	}


	public function service_me_content_infos2(){
		$this->assign('uid',cookie('uid'));
		$service_id = I('get.service_id');
		if(!$service_id){
			exit;
		}
		$path = 'Service/Template/Service_me/'.cookie('uid').'/'.$service_id.'/';
		if(!is_dir($path)){
			mkdir($path,0777,true);
		}

		$where['info_uid'] = cookie('uid');
		$where['info_stat'] = array('neq',4);
		$fields = array('fields'=>array('info_id','info_stat','info_title,info_ctime','info_service_type_id','info_service_type'));

		$m_car = M('Service_info_car');
		$m_exchange = M('Service_info_exchange');
		$m_house = M('Service_info_house');
		$m_job = M('Service_info_job');
		$m_junk = M('Service_info_junk');
		$m_lose = M('Service_info_lose');
		$m_pet = M('Service_info_pet');
		if($service_id == 'none'){
			$pcount = 2;
			$data['fpage'] = '';
			$data['list'] = array();
			$maxid = $m_car->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data_car = Get_Fpage_Ajax($m_car,$fields,$where,$order = 'info_id desc',$pcount);

			$maxid = $m_exchange->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data_exchange = Get_Fpage_Ajax($m_exchange,$fields,$where,$order = 'info_id desc',$pcount);

			$maxid = $m_house->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data_house = Get_Fpage_Ajax($m_house,$fields,$where,$order = 'info_id desc',$pcount);

			$maxid = $m_job->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data_job = Get_Fpage_Ajax($m_job,$fields,$where,$order = 'info_id desc',$pcount);

			$maxid = $m_junk->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data_junk = Get_Fpage_Ajax($m_junk,$fields,$where,$order = 'info_id desc',$pcount);

			$maxid = $m_lose->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data_lose = Get_Fpage_Ajax($m_lose,$fields,$where,$order = 'info_id desc',$pcount);

			$maxid = $m_pet->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data_pet = Get_Fpage_Ajax($m_pet,$fields,$where,$order = 'info_id desc',$pcount);

			if(count($data_car['list'])>0){
				if(!$data['fpage']){
					$data['fpage'] = $data_car['fpage'];
				}
				$data['list'] = array_merge($data['list'],$data_car['list']);
			}

			if(count($data_exchange['list'])>0){
				if(!$data['fpage']){
					$data['fpage'] = $data_exchange['fpage'];
				}
				$data['list'] = array_merge($data['list'],$data_exchange['list']);
			}	

			if(count($data_house['list'])>0){
				if(!$data['fpage']){
					$data['fpage'] = $data_house['fpage'];
				}
				$data['list'] = array_merge($data['list'],$data_house['list']);
			}	

			if(count($data_job['list'])>0){
				if(!$data['fpage']){
					$data['fpage'] = $data_job['fpage'];
				}
				$data['list'] = array_merge($data['list'],$data_job['list']);
			}	

			if(count($data_junk['list'])>0){
				if(!$data['fpage']){
					$data['fpage'] = $data_junk['fpage'];
				}
				$data['list'] = array_merge($data['list'],$data_junk['list']);
			}	

			if(count($data_lose['list'])>0){
				if(!$data['fpage']){
					$data['fpage'] = $data_lose['fpage'];
				}
				$data['list'] = array_merge($data['list'],$data_lose['list']);
			}	

			if(count($data_pet['list'])>0){
				if(!$data['fpage']){
					$data['fpage'] = $data_pet['fpage'];
				}
				$data['list'] = array_merge($data['list'],$data_pet['list']);
			}	
			foreach($data['list'] as $v){
				$temp = '';
				foreach($data['list'] as $k2=>$v2){
					if($k2 < count($data['list'])-1){
						if($data['list'][$k2]['info_ctime'] < $data['list'][$k2+1]['info_ctime']){
							$temp = $data['list'][$k2];
							$data['list'][$k2] = $data['list'][$k2+1];
							$data['list'][$k2+1] = $temp;
						}
					}
				}
			}
		}else{
			$pcount = 5;
			$where['info_service_type_id'] = $service_id;
			$m_temp = $this->get_m($service_id);
			$maxid = $m_temp->max('info_id');
			if($maxid > 40000){
				$where['info_id'] = array('gt',$maxid - 40000);
			}else{
				$where['info_id'] = array('gt',0);
			}
			$data = Get_Fpage_Ajax($m_temp,$fields,$where,$order = 'info_id desc',$pcount);
		}
		$this->assign('data',$data);
		echo $res = $this->fetch('Index/Service_me/service_me_content_infos');
		$file_name = I('get.file_name');
		file_put_contents("{$path}{$file_name}.html", $res);
	}



	//删除指定信息
	public function service_me_content_infos_del(){
		$file_name = I('get.file_name');
		$info_id = I('get.info_id');
		$service_id = I('get.service_id');
		$m = $this->get_m($service_id);
		echo $st = $m->data(array('info_stat'=>0,'info_id'=>$info_id))->save();
		unlink("Service/Template/Service_detail/{$file_name}.html");
	}




//===== service_issue 相关

	//获取所有服务列表
	public function service_issue_serviceList(){
		$m_serviceType = M('Service_type');
		$res_serviceType = $m_serviceType->select();
		$this->assign('res_serviceType',$res_serviceType);
		//$data = $this->fetch('Index/Service_issue/service_issue_serviceList');
		$data = $this->fetch();
		echo $data;
		if(!is_dir('Service/Template/Service_issue')){
			mkdir('Service/Template/Service_issue','0755',true);
		}
		file_put_contents('Service/Template/Service_issue/service_issue_serviceList.html', $data);
	}


	//获取服务设置下的条件表单项
	public function service_issue_serviceList_condition(){
		$service = explode(',',I('get.service'));
		$service_id = $service[0];
		$service_name = $service[1];
		$this->assign('service_id',$service[0]);
		$this->assign('service_name',$service[1]);
		$m_serviceCondition = M('Service_condition');
		//获取当前选择服务下的子级分类
		$res_serviceCondition = $m_serviceCondition->where(array('cond_service_id'=>$service_id))->select(); 
		$cond = $cond2 = array();
		//遍历子级分类 
		foreach($res_serviceCondition as $k=>$v){
			if($v['cond_level'] == 1 && $v['cond_view'] == 1){
				$cond[] = $v; //存储一级且为显示状态的子分类
			}else{
				$cond2[] = $v; 
			}
		}
		//将二级子类合并到一级子类下
		foreach($cond as $k=>$v){
			foreach($cond2 as $k2=>$v2){
				if($v['cond_id'] == $v2['cond_parent']){
					$arr[] = $v2;
				}
			}
			$cond[$k]['cond2'] = $arr;
			$arr='';
		}
		$this->assign('cond',$cond);

		$this->assign('year',date('Y'));
		switch($service_name){
			case '二手物品':	
				$action_name = 'service_issue_serviceList_condition_exchange'; 	//出兑信息
			break;
			case '宠物交易':	
				$action_name = 'service_issue_serviceList_condition_pet'; 	//出兑信息
			break;
			case '寻人寻物':	
				$action_name = 'service_issue_serviceList_condition_lose'; 	//失物招领
			break;
			case '房屋租售':	
				$action_name = 'service_issue_serviceList_condition_house'; 	//出兑信息
			break;
			case '出兑信息':	
				$action_name = 'service_issue_serviceList_condition_junk'; 	//出兑信息
			break;
			case '求职招聘':	
				$action_name = 'service_issue_serviceList_condition_job'; 	//出兑信息
			break;
			case '二手车辆':
				$action_name = 'service_issue_serviceList_condition_car'; 	//出兑信息
			break;
		}
		$data = $this->fetch();
		echo $data;
		file_put_contents('Service/Template/Service_issue/'.$action_name.'.html', $data);
	}






//===== service_index 相关

	//-- 获取服务列表
	public function service_index_conditionArea(){
		$m_serviceTpe = M('Service_type');
		$res_serviceType = $m_serviceTpe->select();
		foreach($res_serviceType as $k=>$v){
			$tmp = '';
			foreach($res_serviceType as $k2=>$v2){
				if($k2+1 < count($res_serviceType)){
					if($res_serviceType[$k2]['type_order'] > $res_serviceType[$k2+1]['type_order']){
						$tmp = $res_serviceType[$k2];
						$res_serviceType[$k2] = $res_serviceType[$k2+1];
						$res_serviceType[$k2+1] = $tmp;
					}
				}
			}
		}
		$this->assign('current_city',C("City_Name"));
		$this->assign('res_serviceType',$res_serviceType);
		echo $content = $this->fetch();
		file_put_contents('Service/Template/Service_index/service_index_conditionArea.html', $content);
	}

	//-- 获取服务下的分类条件
	public function service_index_conditionArea_sub(){
		$service_id = I('get.service_id');
		$m = M('Service_condition');
		$res = $m->where(array('cond_service_id'=>$service_id))->select();
		//dump($res);
		$data = $data_v2 = array();
		foreach($res as $k=>$v){
			if($v['cond_level'] == 1){
				$data[] = $v;
			}else{
				$data_v2[] = $v;
			}
		}
		foreach($data as $k=>$v){
			foreach($data_v2 as $k2=>$v2){
				if($v['cond_id'] == $v2['cond_parent']){
					$tmp[] = $v2;
				}
			}
			$data[$k]['cond_level2'] = $tmp;
			$tmp = '';
		}
		$this->assign('data',$data);
	//	dump($data);
		//echo $content = $this->fetch('Index/Service_index/service_index_conditionArea_sub');
		echo $content = $this->fetch();
		if(!is_dir('Service/Template/Service_index')){
			mkdir('Service/Template/Service_index','0755',true);
		}
		file_put_contents("Service/Template/Service_index/service_index_conditionArea_sub_{$service_id}.html", $content);
	}


	public function create_page($file_name,$content){
		file_put_contents("Service/Template/Service_index/{$file_name}.html", $content);
	}

	//-- 获取综合信息
	public function service_index_infos(){
		$file_name = I('get.file_name');
		$city1 = I('get.city1');
		$city2 = I('get.city2');
		$city3 = I('get.city3');
		$where['info_city1_id'] = $city1;
		if($city2 != 'all'){
			$where['info_city2_id'] = $city2;
		}
		if($city3 != 'all'){
			$where['info_city3_id'] = $city3;
		}
		$limit = 10000;		//设置数据倒查基数

		if(I('get.service_id') != 'none'){		//设置查询条数
			$pcount = 5;		
		}else{
			if(I('get.search')){
				$pcount = 5;		//如果没指定服务则查询所有服务，每个2条
			}else{
				$pcount = 5;		//如果没指定服务则查询所有服务，每个2条
			}
		}
		//判断搜索条件
		if(I('get.search')){
			$search = I('get.search');
			switch(I('get.search_select')){
				case 'none':
					$where['info_title|info_content'] = array('like',array("%{$search}%"));
				break;
				case 'title':
					$where['info_title'] = array('like',array("%{$search}%"));
				break;
				case 'content':
					$where['info_content'] = array('like',array("%{$search}%"));
				break;
			}
		}


		//注册当前生成时间
		$this->assign('timestamp',time()*1000);


		//exchange  外兑信息表
		$m_exchange = M('Service_info_exchange');
		$res_exchange_maxId = $m_exchange->max('info_id');
		if($res_exchange_maxId > $limit){
			$where['info_id'] = array('gt',$res_exchange_maxId - $limit);
		}else{
			$where['info_id'] = array('gt',0);
		}
		$where['info_stat'] = 2;
		$fields_exchange = array(
            'fields'=>array('info_id,info_service_type_id,info_ctime,info_stat,info_title,info_city1,info_city2,info_city3,info_service_type,info_cond_type,info_cond_industry,info_cond_price')
        );
        if(I('get.service_name') == '出兑信息'){
        	I('get.condtype')=='none'?:$where['info_cond_type_id'] = I('get.condtype');
        	I('get.condindustry')=='none'?:$where['info_cond_industry_id'] = I('get.condindustry');
        	I('get.condprice')=='none'?:$where['info_cond_price_id'] = I('get.condprice');
			$data_exchange = Get_Fpage_Ajax($m_exchange,$fields_exchange,$where,$order = 'info_id desc',$pcount);
			$this->assign('data',$data_exchange);
			//$content = $this->fetch('Index/Service_index/service_index_infos');
			$content = $this->fetch();
			echo $content;
			$this->create_page($file_name,$content);
			exit;
        }else{
			$data_exchange = Get_Fpage_Ajax($m_exchange,$fields_exchange,$where,$order = 'info_id desc',$pcount);
        }

		//宠物信息
		$m_pet = M('Service_info_pet');
		$res_pet_maxId = $m_pet->max('info_id');
		if($res_pet_maxId > $limit){
			$where['info_id'] = array('gt',$res_pet_maxId - $limit);
		}else{
			$where['info_id'] = array('gt',0);
		}
		$fields_pet = array(
            'fields'=>array('info_id,info_service_type_id,info_ctime,info_stat,info_title,info_city1,info_city2,info_city3,info_service_type,info_cond_type,info_cond_animal_type,info_cond_price')
        );
        if(I('get.service_name') == '宠物交易'){
        	I('get.condtype')=='none'?:$where['info_cond_type_id'] = I('get.condtype');
        	I('get.condprice')=='none'?:$where['info_cond_price_id'] = I('get.condprice');
        	I('get.condanimal')=='none'?:$where['info_cond_animal_type_id'] = I('get.condanimal');
			$data_pet = Get_Fpage_Ajax($m_pet,$fields_pet,$where,$order = 'info_id desc',$pcount);
			$this->assign('data',$data_pet);
			//$content = $this->fetch('Index/Service_index/service_index_infos');
			$content = $this->fetch();
			echo $content;
			$this->create_page($file_name,$content);
			exit;
        }else{
			$data_pet = Get_Fpage_Ajax($m_pet,$fields_pet,$where,$order = 'info_id desc',$pcount);
        }
		//dump($data_pet);

		//寻物寻人
		$m_lose = M('Service_info_lose');
		$res_lose_maxId = $m_lose->max('info_id');
		if($res_lose_maxId > $limit){
			$where['info_id'] = array('gt',$res_lose_maxId - $limit);
		}else{
			$where['info_id'] = array('gt',0);
		}
		$fields_lose = array(
            'fields'=>array('info_id,info_service_type_id,info_ctime,info_stat,info_title,info_city1,info_city2,info_city3,info_service_type,info_cond_type')
        );
        if(I('get.service_name') == '寻物寻人'){
        	I('get.condtype')=='none'?:$where['info_cond_type_id'] = I('get.condtype');
			$data_lose = Get_Fpage_Ajax($m_lose,$fields_lose,$where,$order = 'info_id desc',$pcount);
			echo '<pre>';
			//var_dump($data_lose);
			echo '</pre>';
			$this->assign('data',$data_lose);
			//$content = $this->fetch('Index/Service_index/service_index_infos');
			$content = $this->fetch();
			echo $content;
			$this->create_page($file_name,$content);
			exit;
        }else{
			$data_lose = Get_Fpage_Ajax($m_lose,$fields_lose,$where,$order = 'info_id desc',$pcount);
        }
		//dump($data_lose);

		//房屋
		$m_house = M('Service_info_house');
		$res_house_maxId = $m_house->max('info_id');
		if($res_house_maxId > $limit){
			$where['info_id'] = array('gt',$res_house_maxId - $limit);
		}else{
			$where['info_id'] = array('gt',0);
		}
		$fields_house = array(
            'fields'=>array('info_id,info_service_type_id,info_ctime,info_stat,info_title,info_city1,info_city2,info_city3,info_service_type,info_cond_type,info_cond_shape,info_cond_area,info_cond_price')
        );
        if(I('get.service_name') == '房屋租售'){
        	I('get.condtype')=='none'?:$where['info_cond_type_id'] = I('get.condtype');
        	I('get.condprice')=='none'?:$where['info_cond_price_id'] = I('get.condprice');
        	I('get.condshape')=='none'?:$where['info_cond_shape_id'] = I('get.condshape');
        	I('get.condarea')=='none'?:$where['info_cond_area_id'] = I('get.condarea');
			$data_house = Get_Fpage_Ajax($m_house,$fields_house,$where,$order = 'info_id desc',$pcount);
			$this->assign('data',$data_house);
			//$content = $this->fetch('Index/Service_index/service_index_infos');
			$content = $this->fetch();
			echo $content;
			$this->create_page($file_name,$content);
			exit;
        }else{
			$data_house = Get_Fpage_Ajax($m_house,$fields_house,$where,$order = 'info_id desc',$pcount);
        }
		//dump($data_house);

		//旧货
		$m_junk = M('Service_info_junk');
		$res_junk_maxId = $m_junk->max('info_id');
		if($res_junk_maxId > $limit){
			$where['info_id'] = array('gt',$res_junk_maxId - $limit);
		}else{
			$where['info_id'] = array('gt',0);
		}
		$fields_junk = array(
            'fields'=>array('info_id,info_service_type_id,info_ctime,info_stat,info_title,info_city1,info_city2,info_city3,info_service_type,info_cond_type,info_cond_goods_type,info_cond_price')
        );
        if(I('get.service_name') == '二手物品'){
        	I('get.condtype')=='none'?:$where['info_cond_type_id'] = I('get.condtype');
        	I('get.condprice')=='none'?:$where['info_cond_price_id'] = I('get.condprice');
        	I('get.condgoods')=='none'?:$where['info_cond_goods_type_id'] = I('get.condgoods');
			$data_junk = Get_Fpage_Ajax($m_junk,$fields_junk,$where,$order = 'info_id desc',$pcount);
			$this->assign('data',$data_junk);
			//$content = $this->fetch('Index/Service_index/service_index_infos');
			$content = $this->fetch();
			echo $content;
			$this->create_page($file_name,$content);
			exit;
        }else{
			$data_junk = Get_Fpage_Ajax($m_junk,$fields_junk,$where,$order = 'info_id desc',$pcount);
        }
		//dump($data_junk);


		//招聘
		$m_job = M('Service_info_job');
		$res_job_maxId = $m_job->max('info_id');
		if($res_job_maxId > $limit){
			$where['info_id'] = array('gt',$res_job_maxId - $limit);
		}else{
			$where['info_id'] = array('gt',0);
		}
		$fields_job = array(
            'fields'=>array('info_id,info_service_type_id,info_ctime,info_stat,info_title,info_city1,info_city2,info_city3,info_service_type_id,info_service_type,info_cond_type,info_cond_price,info_cond_edu,info_cond_experience,info_cond_industry')
        );
        if(I('get.service_name') == '求职招聘'){
        	I('get.condtype')=='none'?:$where['info_cond_type_id'] = I('get.condtype');
        	I('get.condprice')=='none'?:$where['info_cond_price_id'] = I('get.condprice');
        	I('get.condedu')=='none'?:$where['info_cond_edu_id'] = I('get.condedu');
        	I('get.condexperience')=='none'?:$where['info_cond_experience_id'] = I('get.condexperience');
        	I('get.condindustry')=='none'?:$where['info_cond_industry_id'] = I('get.condindustry');
			$data_job = Get_Fpage_Ajax($m_job,$fields_job,$where,$order = 'info_id desc',$pcount);
			$this->assign('data',$data_job);
			//$content = $this->fetch('Index/Service_index/service_index_infos');
			$content = $this->fetch();
			echo $content;
			$this->create_page($file_name,$content);
			exit;
        }else{
			$data_job = Get_Fpage_Ajax($m_job,$fields_job,$where,$order = 'info_id desc',$pcount);
        }
		//dump($data_job);


		//二手车
		$m_car = M('Service_info_car');
		$res_car_maxId = $m_car->max('info_id');
		if($res_car_maxId > $limit){
			$where['info_id'] = array('gt',$res_car_maxId - $limit);
		}else{
			$where['info_id'] = array('gt',0);
		}
		$fields_car = array(
            'fields'=>array('info_id,info_service_type_id,info_ctime,info_stat,info_title,info_city1,info_city2,info_city3,info_service_type,info_cond_type,info_cond_car_type,info_cond_brand,info_cond_price')
        );
        if(I('get.service_name') == '二手车辆'){
        	I('get.condtype')=='none'?:$where['info_cond_type_id'] = I('get.condtype');
        	I('get.condprice')=='none'?:$where['info_cond_price_id'] = I('get.condprice');
        	I('get.condbrand')=='none'?:$where['info_cond_brand_id'] = I('get.condbrand');
        	I('get.condcar_type')=='none'?:$where['info_cond_car_type_id'] = I('get.condcar_type');
        	I('get.conduse_year')=='none'?:$where['info_cond_use_year_id'] = I('get.conduse_year');
			$data_car = Get_Fpage_Ajax($m_car,$fields_car,$where,$order = 'info_id desc',$pcount);
			$this->assign('data',$data_car);
			//$content = $this->fetch('Index/Service_index/service_index_infos');
			$content = $this->fetch();
			echo $content;
			$this->create_page($file_name,$content);
			exit;
        }else{
			$data_car = Get_Fpage_Ajax($m_car,$fields_car,$where,$order = 'info_id desc',$pcount);
        }


		//合并数据
		$data['fpage'] = '';
		$data['list'] = array();
		if(count($data_exchange['list']) > 0){

			$data['list'] = array_merge($data['list'],$data_exchange['list']);
			if($data['fpage'] == ''){
				$data['fpage'] = $data_exchange['fpage'];
			}
		}
		if(count($data_pet['list']) > 0){
			$data['list'] = array_merge($data['list'],$data_pet['list']);
			if($data['fpage'] == ''){
				$data['fpage'] = $data_exchange['fpage'];
			}
		}
		if(count($data_lose['list']) > 0){
			$data['list'] = array_merge($data['list'],$data_lose['list']);
			if($data['fpage'] == ''){
				$data['fpage'] = $data_exchange['fpage'];
			}
		}
		if(count($data_house['list']) > 0){
			$data['list'] = array_merge($data['list'],$data_house['list']);
			if($data['fpage'] == ''){
				$data['fpage'] = $data_exchange['fpage'];
			}
		}
		if(count($data_junk['list']) > 0){
			$data['list'] = array_merge($data['list'],$data_junk['list']);
			if($data['fpage'] == ''){
				$data['fpage'] = $data_exchange['fpage'];
			}
		}
		if(count($data_job['list']) > 0){
			$data['list'] = array_merge($data['list'],$data_job['list']);
			if($data['fpage'] == ''){
				$data['fpage'] = $data_exchange['fpage'];
			}
		}
		if(count($data_car['list']) > 0){
			$data['list'] = array_merge($data['list'],$data_car['list']);
			if($data['fpage'] == ''){
				$data['fpage'] = $data_exchange['fpage'];
			}
		}

		
		foreach($data['list'] as $k=>$v){
			$tmp = '';
			foreach($data['list'] as $k2=>$v2){
				if($k2+1 < count($data['list'])){
					if($data['list'][$k2]['info_ctime'] < $data['list'][$k2+1]['info_ctime']){
						$tmp = $data['list'][$k2];
						$data['list'][$k2] = $data['list'][$k2+1];
						$data['list'][$k2+1] = $tmp;
					}
				}
			}
		}
		$this->assign('data',$data);
		$content = $this->fetch();
		echo $content;
		$this->create_page($file_name,$content);
	}


}